<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?php
require_once("conn.php");

$id = checkTrim($_POST['id']);
$title = checkTrim($_POST['title']);
$content = checkTrim($_POST['content']);
$isModify = checkTrim($_POST['isModify']);

$db = new DBC();

if ($isModify == 1) {
    $sql = "UPDATE t_announce SET title = '" . $title . "',content = '" . $content . "' WHERE id = " . $id;
} else {
    $sql = "INSERT INTO t_announce(title,content,status,createTime) VALUES('" . $title . "','" . $content . "',0,now())";
}

$transfer = "announceList.php?menu=announce";
if ($db->execute($sql)) {
    //success
    //    echo "<script language='javascript'>alert('成功'); </ script>";
    echo "<script language='javascript'>location='" . $transfer . "';</script>";
} else {
    //failue
    echo "<script language='javascript'>alert('失败'); </script>";
    echo "<script language='javascript'>history.back();</script>";
}

function checkTrim($item) {
    if (isset($item)) {
        $item = trim($item);
    } else {
        $item = "";
    }
    return $item;
}
?>
